//
// Created by xili on 2024/8/21 16:01.
// GO BIG OR GO HOME.
//
#include "leetcode.h"

class Solution {
public:
    vector<int> occurrencesOfElement(vector<int> &nums, vector<int> &queries, int x) {
        unordered_map<int, int> ump;
        int n = nums.size();
        int j = 1;
        for (int i = 0; i < n; i++) {
            if (nums[i] == x) {
                ump[j++] = i;
            }
        }
        vector<int> ans;
        for (auto &item: queries) {
            ans.push_back(item > j - 1 ? -1 : ump[item]);
        }
        return ans;
    }
};